package com.ruoyi.hr.controller.hr.changemanage.internshipchangejust;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.changemanage.internshipchange.InternshipChangeService;
import com.ruoyi.hr.service.changemanage.internshipchangejust.InternshipChangeJustService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @author zeo
 * @explain 实习转正登记
 * @date 2020/3/10
 */
@Controller
@RequestMapping("/changeManage/InternshipChangeJust")
public class InternshipChangeJustController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    InternshipChangeJustService internshipChangeJustService;

    @Autowired
    InternshipChangeService internshipChangeService;

    private String prefix = "hr/changemanage/internshipchangejust";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String internshipChangeJust() {
        return prefix + "/internshipChangeJust";
    }

    @GetMapping("/add")
    public String addInternshipChangeJustEmp() {
        return prefix + "/addInternshipChangeJustEmp";
    }

    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(internshipChangeJustService.findInternshipChangeJustListData(map, authority));
    }

    @RequestMapping("/findInternshipChangeJustEmp")
    @ResponseBody
    public TableDataInfo findInternshipChangeJustEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(internshipChangeJustService.findInternshipChangeJustEmp(map, authority));
    }

    /**
     * 执行添加员工存储过程
     */
    @PostMapping("/addInternshipChangeJustEmp")
    @ResponseBody
    public BaseResult addInternshipChangeJustEmp(String allEid) {
        return internshipChangeJustService.addInternshipChangeJustEmp(allEid);
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editInternshipJustEmp", internshipChangeJustService.findInternshipChangeJustData(id));
        return prefix + "/editInternshipJustEmp";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map){
        return toAjax(internshipChangeJustService.editInternshipJustEmp(map));
    }

    /**
     * 数据确认,取消确认,执行
     */
    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String procedure) {
        return internshipChangeService.procedure(allId, procedure);
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(internshipChangeService.removeData(ids));
    }


    @GetMapping("/history")
    public String history(){
        return prefix +"/history";
    }

    @RequestMapping("/historyList")
    @ResponseBody
    public TableDataInfo historyList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(internshipChangeJustService.historyList(map, authority));
    }
}
